<?php
/**
 * Created by PhpStorm.
 * User: lxd
 * Date: 2018/7/24
 * Time: 14:18
 * Comm:
 */
//payments

require './secode.php';

//支付方式
$payer      = new \PayPal\Api\Payer();
$payer->setPaymentMethod( 'paypal' );

//商品列表
$item       = new \PayPal\Api\Item();
$item->setName( 'hello123' )->setCurrency( 'USD' )->setQuantity( 1 )->setSku( '1234' )->setPrice( '100' );

$items      = new \PayPal\Api\ItemList();
$items->addItem( $item );

//账单详情
$details    = new \PayPal\Api\Details();
$details->setSubtotal( 100 );

$amount     = new \PayPal\Api\Amount();
$amount->setCurrency( 'USD' )->setTotal( 100 )->setDetails( $details );

//交易
$transaction        = new \PayPal\Api\Transaction();
$transaction->setAmount( $amount )->setItemList( $items )->setDescription( 'payment description' );

//return url
$redireurls         = new \PayPal\Api\RedirectUrls();
$redireurls->setCancelUrl( $baseUrl . 'payment_cancel_url.php' )->setReturnUrl( $baseUrl . 'payment_return_url.php' );


$payment        = new \PayPal\Api\Payment();
$payment->setIntent( 'sale' )->setPayer( $payer )->setRedirectUrls( $redireurls )->setTransactions( [$transaction] );

$payment->create( $apiContext );


$redireurl      = $payment->getApprovalLink();

var_dump( $redireurl );

//header( 'location: ' . $redireurl );
//exit();